import { InputQuestion, QuestionBase, TimeQuestion, SelectQuestion } from '@/components/public-template';
import { TextTable } from '@/components/public-template';
import { TableBase } from '@/components/public-template';
import { Api as ApiSystem } from '@/config/api/system';
import { Api as apiPlan } from '@/config/api/archivesCollectPlan';

class HomeService {
  getQuestions() {
    const questions: QuestionBase<any>[] = [
      new InputQuestion({
        key: 'name',
        label: '计划名称',
        value: null
      }),
      new SelectQuestion({
        key: 'departmentIds',
        label: '部门',
        value: [],
        defaultValue: [],
        type: 'tree',
        state: {
          url: ApiSystem.orgTreeData,
          protType: 'post',
          nameKey: 'name',
          nameValue: 'id',
          nameChildren: 'childOrg'
          // treeCheckable: true
        }
      }),
      new TimeQuestion({
        key: 'startTime',
        label: '创建时间',
        value: [],
        state: {
          showTime: true,
          format: 'YYYY-MM-DD HH:mm:ss',
          valueFormat: 'YYYY-MM-DD HH:mm:ss',
          keySplit: ['startTime', 'endTime']
        }
      })
    ];
    return questions;
  }
  getTables() {
    const tables: TableBase<any>[] = [
      new TextTable({
        key: 'code',
        value: '计划编码',
        type: 'router',
        columns: {
          width: 150
        },
        state: {
          type: 'local',
          showType: 'VIEW'
        }
      }),
      new TextTable({
        key: 'name',
        value: '计划名称'
      }),
      new TextTable({
        key: 'description',
        value: '描述'
      }),
      new TextTable({
        key: 'dept',
        value: '部门',
        type: 'slot',
        state: {
          slotName: 'deptName'
        }
      }),
      new TextTable({
        key: 'men',
        value: '执行人',
        type: 'slot',
        state: {
          slotName: 'menName'
        }
      }),
      new TextTable({
        key: 'frequencyNum',
        value: '执行频率',
        type: 'slot',
        state: {
          filterName: 'CYCLE',
          slotName: 'frequencyTime'
        }
      }),
      new TextTable({
        key: 'warningPeriod',
        value: '预警期（天）'
      }),
      new TextTable({
        key: 'planCreateTime',
        value: '计划开始时间',
        columns: {
          width: 160
        }
      }),
      new TextTable({
        key: 'planEndTime',
        value: '计划结束时间',
        columns: {
          width: 160
        }
      }),
      new TextTable({
        key: 'status',
        value: '状态',
        type: 'slot',
        state: {
          slotName: 'stateSwitch'
        }
      }),
      new TextTable({
        key: 'creatorName',
        value: '创建人'
      }),
      new TextTable({
        key: 'createdTime',
        value: '创建时间',
        columns: {
          width: 160
        }
      }),
      new TextTable({
        key: 'actions',
        value: '操作',
        columns: {
          fixed: 'right',
          width: 80
        },
        handle: [
          {
            type: 'delete',
            text: '删除',
            class: 'text-primary',
            url: apiPlan.planDelete,
            postType: 'post',
            urlName: 'id',
            state: {}
          }
        ]
      })
    ];
    return tables;
  }
  getIcons() {
    const icons: TableBase<any>[] = [
      new TextTable({
        key: 'local',
        value: '添加',
        type: 'primary',
        class: 'icon-add',
        state: {}
      }),
      new TextTable({
        key: 'delete',
        value: '删除',
        type: 'default',
        class: 'icon-delete',
        state: {
          type: 'array',
          postType: 'post',
          url: apiPlan.planDelBatch
        }
      })
    ];
    return icons;
  }
}

export default new HomeService();
